const mysql = require("mysql");

let mysqlcon = mysql.createConnection({host:"127.0.0.1",port:"3306",user:"root",password:"root",database:"mydb"});

mysqlcon.connect();
function toQuery(sql)
{
    return new Promise((resolve,reject)=>{
        mysqlcon.query(sql,(err,data)=>{
            if(err)
            {
                resolve([false,"获取信息失败"]);
            }
            else
            {
                resolve([true,data]);
            }
        })
    })
}

async function togetdata(sql)
{
    let [flag,data] = await toQuery(sql);
    if(flag)
    {
        return data;
    }
    else
    {
        return data;
    }
}
// togetdata("select * from stuinfo");
module.exports = togetdata;